package com.homson.coreservice.serviceinfrastructure.converter;


import com.homson.coreservice.servicecommon.enumeration.TransTypeEnum;
import com.homson.coreservice.serviceinfrastructure.datasource.model.account.TransactionDO;
import com.homson.coreservice.serviceinfrastructure.dto.TransactionDto;

import java.util.List;
import java.util.Objects;

/**
 * @author: homson_leo
 * @contact: hey_超级巨星（Homson_Leo）- 刘泓岑 1196816884@qq.com
 * @time: 2025/11/1 3:16 PM
 **/
public class TransactionConverter {
    public static TransactionDto convert(TransactionDO transactionDO) {
        if(Objects.isNull(transactionDO)){
            return null;
        }
        TransactionDto transactionDto = new TransactionDto();
        transactionDto.setTransDate(transactionDO.getTransDate());
        transactionDto.setAccountId(transactionDO.getAccountId());
        transactionDto.setAmount(transactionDO.getAmount());
        transactionDto.setTransType(TransTypeEnum.valueOf(transactionDO.getType()));
        transactionDto.setDescription(transactionDO.getDescription());
        return transactionDto;
    }
    
    public static List<TransactionDto> convert(List<TransactionDO> transactionDOList) {
        return transactionDOList.stream().map(TransactionConverter::convert).toList();
    }
}
